module ApplicationHelper
  def dynamic_background
    # 动态背景
    if is_fullscreen_play?
      'none'
    else
      if current_page?(mine_song_fav_path) ||
        current_page?(mine_picklist_path) ||
        current_page?(mine_history_path) ||
        current_page?(playlist_path(params[:id] ||= 1)) ||
        current_page?(singer_path(params[:id] ||= 1))
        'mine_hollow_cover'
      elsif current_page?(mine_playlist_fav_path)
        'mine_cover'
      else
        'blue'
      end
    end
  end

  def is_fullscreen_play?
    current_page?(controller: 'fullscreen_play', action: 'index')
  end

  def is_matched_route?(url)
    url === request.path
  end

  def logo_box_less
    current_page?(controller: 'fullscreen_play', action: 'index')
  end

  def search_box_less
    current_page?('/search') ||
      current_page?(controller: 'fullscreen_play', action: 'index') ||
      current_page?(controller: "singers", action: "choose")
  end

  def has_footer
    current_page?(root_url) ||
      current_page?(mine_path) ||
      current_page?(controller: 'recommend', action: 'index') ||
      current_page?(controller: 'rank', action: 'index') ||
      current_page?(controller: 'playlists', action: 'index') ||
      current_page?(controller: 'mvs', action: 'index') ||
      current_page?(controller: 'singers', action: 'index') ||
      current_page?(controller: 'test', action: 'index')
  end

  def footer_navigation
    list = [
      {
        id: "mine",
        name: '我的',
        path: mine_path
      },
      {
        name: '|'
      },
      {
        id: "recommend",
        name: '推荐',
        path: recommend_path
      },
      {
        id: "rank",
        name: '排行',
        path: rank_path
      },
      {
        id: "playlists",
        name: '歌单',
        path: playlists_path
      },
      {
        id: "mv",
        name: 'MV',
        path: mvs_path
      },
      {
        id: "singers",
        name: '歌手',
        path: singers_path
      },
    ]
    list.push({
                id: "test",
                name: '测试',
                path: test_path
              },) unless Rails.env.production?
    list
  end

  def item_href_url(item)
    item.class == Playlist ? playlist_path(id: item.id, prev_url: mine_playlist_fav_path) : singer_path(id: item.id, prev_url: mine_playlist_fav_path)
  end

  def item_image_url(item)
    item.class == Playlist ? "/images/playlists/p#{item[:serial_id]}.jpeg" : "/images/singers/#{item[:name]}.jpeg"
  end
end
